# -*- coding: utf-8 -*-

import pandas as pd
from auto_correct import Speller

spell = Speller('ug')
input_file = './spell_input.txt'
output_file = './spell_output.csv'


def getWordOutput(word, mode='exist'):
    return spell.autocorrect_sentence(word, mode=mode)


def getWordListOutput(file=input_file):
    words_df = pd.read_csv(file, header=None, encoding='utf-8-sig')
    words_df.columns = ['word']
    words_df['output_exist'] = words_df['word'].apply(getWordOutput)
    words_df['output_normal'] = words_df['word'].apply(lambda x: getWordOutput(x, mode='normal'))

    print(words_df['output_exist'])
    words_df.to_csv(output_file, encoding='utf-8-sig')
#
# spell = Speller('ug')
#
# res = spell.existing('مودا مودام')
# print(res)
#
# result = spell.autocorrect_word('任何人')
# print('normal:', result)
# result = spell.autocorrect_word('任何人', mode='exist')
# print('exist:', result)
# result = spell.autocorrect_sentence('任何人 - 。 مودام 任何人 مودا', mode='exist')
# print('exist:', result)

result = spell.get_candidates('مود')
print(result)
result = spell.autocorrect_word('مود')
print(result)
result = spell.autocorrect_word('مود', mode='exist')
print(result)

# result = spell.get_candidates('oppo')
# print(result)
# result = spell.autocorrect_word('oppo')
# print(result)
# result = spell.autocorrect_word('oppo', mode='exist')
# print(result)

# result = spell.autocorrect_sentence(' شەپكە', mode='exist')
# print('data:', result)
# result = spell.autocorrect_sentence(' شەپە', mode='exist')
# print('data:', result)

#
# result = spell.autocorrect_sentence('چارۋىچىلىقىداقوي')
# print(result)
# result = spell.autocorrect_sentence('چارۋىچىلىقىداقوي', mode='exist')
# print(result)
#
# result = spell.autocorrect_sentence('چارۋىچىلىق مەيدانى')
# print(result)
# result = spell.autocorrect_sentence('چارۋىچىلىق مەيدانى', mode='exist')
# print(result)
#
# result = spell.autocorrect_sentence('چارۋىچىلىق مەيدانى چارۋىچىلىقىداقوي')
# print(result)
# result = spell.autocorrect_sentence('چارۋىچىلىق مەيدانى چارۋىچىلىقىداقوي', mode='exist')
# print(result)

# if __name__ == '__main__':
#     getWordListOutput()